{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "Copyright(c) 2025 NVIDIA Corporation. All rights reserved.\n",
    "\n",
    "NVIDIA Corporation and its licensors retain all intellectual property\n",
    "and proprietary rights in and to this software, related documentation\n",
    "and any modifications thereto.Any use, reproduction, disclosure or\n",
    "distribution of this software and related documentation without an express\n",
    "license agreement from NVIDIA Corporation is strictly prohibited."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Add parameters to the config.yaml for the reference workflow\n",
    "\n",
    "This notebook illustrates how you can move your frequently used parameters to the config file for the reference workflow. In the example here, we will move the voice_id parameter used by the default TTS provider (elevenLabs) as a config paramter. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Ensure that the Pre-requisites are met\n",
    "\n",
    "Please run through the steps noted in the setup prequisites notebook to ensure that you have the necessary setup in place.\n",
    "\n",
    "Check the status of the application again by running the following command. \n",
    "\n",
    "Note: You will need to select the python environment to run the notebook for the first time. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!kubectl get po -n app"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Download the ACE Controller Configuration\n",
    "* Ensure that the downloaded ACE Controller configuration is in sync. You can click on the download button again to download the latest version of the configuration. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![ACE Configurator](pictures/ace_configurator_sync.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Edit the `config.yaml` file\n",
    "1. Navigate to the following path in your file system:\n",
    "   ```\n",
    "   ace-controller-ace-controller-deployment -> assets -> app-storage-volume -> configs -> config.yaml\n",
    "   ```\n",
    "2. Open the `config.yaml` file.\n",
    "3. Add the following the following section anywhere, as shown by the sample snippet"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Pipeline:\n",
    "    # Only one of the following LLM service configurations will be active based on this setting:\n",
    "    # - \"NvidiaLLMService\" - Uses the NvidiaLLMService configuration\n",
    "    # - \"NvidiaRAGService\" - Uses the NvidiaRAGService configuration\n",
    "    # - \"OpenAILLMService\" - Uses the OpenAILLMService configuration\n",
    "    llm_processor: \"OpenAILLMService\" # OR NvidiaLLMService OR NvidiaRAGService OR OpenAILLMService\n",
    "    filler:\n",
    "        - \"Let me think\"\n",
    "        - \"Hmmm\"\n",
    "    time_delay: 2.0\n",
    "\n",
    "TTSProcessor:\n",
    "    voice_id: \"XrExE9yKIg1WjnnlVkGX\"\n",
    "\n",
    "UserPresenceProcesssor:\n",
    "    welcome_message: \"Hello\"\n",
    "    farewell_message: \"Bye\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Update the `config.py` file to ensure that the additional configuration is read successfully. The file would be located in the downloaded folder. \n",
    "\n",
    "   ```\n",
    "   ace-controller-ace-controller-deployment -> assets -> app-storage-volume -> src -> config.py\n",
    "   ```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "# Define the pydantic class for your processor in the file. \n",
    "class TTSProcessor(BaseModel):\n",
    "    voice_id: StrictStr = \"XrExE9yKIg1WjnnlVkGX\"\n",
    "\n",
    "# Root model for the pipeline configuration\n",
    "class Config(BaseModel):\n",
    "    Pipeline: Pipeline\n",
    "    TTSProcessor: TTSProcessor  #<------- Add your processor here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Navigate to the `bot.py` in the same folder and now update the code to read the `voice_id` setting from the config.yaml file. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "tts = ElevenLabsTTSServiceWithEndOfSpeech(\n",
    "        api_key=os.getenv(\"ELEVENLABS_API_KEY\"),\n",
    "        voice_id=config.TTSProcessor.voice_id,\n",
    "        sample_rate=16000,\n",
    "        model = \"eleven_flash_v2_5\",\n",
    "    )\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Upload the Changes\n",
    "Save your local changes in VSCode. \n",
    "In the ACE Configurator view in VSCode, click the **Upload** button to upload the modified `config.yaml` file."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![Avatar Controller Upload Config](pictures/upload_config.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Ensure that the changes are finished updating. This might take a few seconds.\n",
    "\n",
    "Once the changes are successfully updated. the ACE Configurator view will show a green `Synced` symbol again for the app-storage-volume. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![Avatar Controller Upload Config](pictures/ace-configurator-synced.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Refresh the Browser UI\n",
    "1. Open the browser UI where the digital human is hosted. (your current URL:30111)\n",
    "2. Refresh the page.\n",
    "3. Start a conversation with the digital human, and you should see it is using the voice_id configured from the config.yaml of your reference workflow."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Conclusion\n",
    "You have successfully reconfigured the ACE digital human and tested the changes. 🎉\n",
    "\n",
    "This particular process of moving settings to the config.yaml can be extended to a multitude of parameters used by the `bot.py` file. The default reference workflow uses limited number of parameters from the config file to maintain simplicity. "
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
